import { Router } from 'express';
import service from '../service/usermanager';
import { AuthError } from '../utils/classModal';

const router = Router();

router.use(({ originalUrl: api }, { locals: { level } }, next) => {
	if (![9, 999].includes(level)) throw new AuthError();
	next();
});

router
	.route('')
	.get(service.getlist) // 列表
	.post(service.add); // 增加
router
	.route('/:id')
	.get(service.getdetail) // 详情
	.put(service.resetpass) // 改
	.delete(service.delete); // 删

module.exports = router;
